/**
 * 权限声明：
 */
package com.handy.webwork;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.handy.webwork.action.ActionMapping;
import com.handy.webwork.action.InvokService;

/**
 * 根据用户请求检索控制器，分发任务。
 * 
 * @author rocken.zeng@gmail.com
 * 
 */
public class Dispatcher {
	private static Log log = LogFactory.getLog(Dispatcher.class);

	private HttpServletRequest request;

	private HttpServletResponse response;

	private ServletContext context;
	
	private ActionMapping actionMapping;
	
	//创建分发器
	public Dispatcher(HttpServletRequest request, HttpServletResponse response,
			ServletContext context,ActionMapping actionMapping) {
		this.request = request;
		this.response = response;
		this.context = context;
		this.actionMapping = actionMapping;
	}

	//分发请求。
	public void invok(){
		try {
			new InvokService(request, response, context).invok(actionMapping);
		} catch (IOException e) {
			log.error(e.getMessage());
		} catch (ServletException e) {
			log.error(e.getMessage());
		}
	}
	
	public void run() {
		invok();
	}
}
